package com.famid.flashcards.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class CardDBHelper extends SQLiteOpenHelper {

	public static final String COLUMN_ID = "_id";
	
	public static final String TABLE_CARDS = "cards";
	public static final String COLUMN_QUESTION = "question";
	public static final String COLUMN_ANSWER = "answer";
	public static final String COLUMN_STATUS = "status";
	public static final String COLUMN_STACK_ID = "stuck_id";
	
	public static final String TABLE_STACK = "stacks";
	public static final String COLUMN_TITLE = "title";
	
//	public static final String TABLE_CARD_STACK = "card_stack";
//	public static final String COLUMN_CARD_ID = "c_id";
//	public static final String COLUMN_STACK_ID = "s_id";

	private static final String DATABASE_NAME = "language_cards.db";
	private static final int DATABASE_VERSION = 1;

	// Database creation sql statement
	private static final String CREATE_CARDS = "create table " + TABLE_CARDS + "( " + COLUMN_ID + " integer primary key autoincrement, " 
		+ COLUMN_QUESTION + " text not null, " 
		+ COLUMN_ANSWER + " text not null, "
		+ COLUMN_STACK_ID + " integer not null, "
		+ COLUMN_STATUS + " text not null);";
	
	private static final String CREATE_STACK = "create table " + TABLE_STACK + "( " + COLUMN_ID + " integer primary key autoincrement, "
		+ COLUMN_TITLE + " text not null);";
	
//	private static final String CREATE_CARD_STACK = "create table " + TABLE_CARD_STACK + "( " + COLUMN_ID + " integer primary key autoincrement, "
//		+ COLUMN_CARD_ID + " integer not null, " 		
//		+ COLUMN_STACK_ID + " integer not null);";

	public CardDBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(CREATE_CARDS);
		database.execSQL(CREATE_STACK);
//		database.execSQL(CREATE_CARD_STACK);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(CardDBHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS" + CREATE_CARDS);
		db.execSQL("DROP TABLE IF EXISTS" + CREATE_STACK);
//		db.execSQL("DROP TABLE IF EXISTS" + CREATE_CARD_STACK);
		onCreate(db);
	}

}